//
//  JoinUsWantedDetailMiddleCell.swift
//  甜言蜜语
//
//  Created by yingli_yanfa_liuxingyu on 16/7/31.
//  Copyright © 2016年 wl. All rights reserved.
//

import UIKit

class JoinUsWantedDetailMiddleCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource {
    @IBOutlet weak var collection: UICollectionView!

    var modelList: [JobWantedModel]?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
        self.collection .registerNib(UINib (nibName: "JoinUsWantJobMiddleCollCell", bundle: nil), forCellWithReuseIdentifier: "JoinUsWantJobMiddleCollCell")
        self.collection.scrollEnabled = false
    }
    
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
   
    func setCellContentWithCellInfo(cellInfo: [JobWantedModel]? ) -> Void {
        
       self.modelList = cellInfo
        self.collection.delegate = self
        self.collection.dataSource = self
        
        self.collection.reloadData()
        
    }
    
    //MARK:UICollectionViewDataSource
    //每一组有多少个cell
    func collectionView(collectionView:UICollectionView,numberOfItemsInSection section: Int) -> Int{
        
        if modelList?.count == nil{
            return 0
        }else{
            return (modelList?.count)!
        }
        
        
    }
    //设置每组的cell的边界
    func collectionView(collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,insetForSectionAtIndex section: Int) -> UIEdgeInsets{
        
        return UIEdgeInsetsMake(10, 10, 10, 10)//上左下右
    }
    //最小行间距
    func collectionView(collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat{
        return 10
    }
    //最小列间距
    func collectionView(collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat{
        return 10
    }
    //设定全局的Cell尺寸
    func collectionView(collectionView: UICollectionView,layout collectionViewLayout: UICollectionViewLayout,sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize{
        
        return CGSizeMake(SCREEN_WIDTH/2-20,100)
        
    }
    //cell上显示的信息
    func collectionView(collectionView: UICollectionView,cellForItemAtIndexPath indexPath: NSIndexPath) ->UICollectionViewCell{
        
        let cell = collection.dequeueReusableCellWithReuseIdentifier("JoinUsWantJobMiddleCollCell", forIndexPath: indexPath) as! JoinUsWantJobMiddleCollCell
        
        let model = modelList![indexPath.row]
        
        cell.iv.sd_setImageWithURL(NSURL(string: model.imgsrc), placeholderImage: UIImage(named: "placeholder"))
        
        return cell
    }
    
    //MARK:UICollectionViewDelegate
    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){
        DetailPictureView.imageDisplay(self.modelList!, index: (self.modelList?.count)! - 1)
    }
    
    
}
